<script setup>
import { reactive } from '@vue/reactivity';
import { onMounted } from '@vue/runtime-core';
import { post } from '../../utils';
let data = reactive({
    list: [],
});
//列表
function getList() {
    post('/api/Admin/GetProductCategoryTreeList', {}).then(function (res) {
        data.list = res.result.list;
    });
}
onMounted(() => {
    getList();
})

//编辑
import EditCategoryDialog from './EditCategoryDialog.vue';
let editDialog = null;

//删除
function deleteData(row) {
    post('/api/Admin/DeleteProductCategory', { id: row.id }).then(res => {
        if (res.success) {
            getList();
        }
    });
}
</script>
<template>
    <div class="mb-2">
        <el-button @click="editDialog.showEdit(0, 0)" type="primary" class="el-icon-plus">添加</el-button>
    </div>

    <el-table :data="data.list" row-key="id" border class="mb-6">
        <el-table-column prop="id" label="编号" width="100"></el-table-column>
        <el-table-column prop="name" label="名称"></el-table-column>
        <el-table-column label="状态">
            <template #default="scope">
                <el-tag v-if="scope.row.visible" type="success">显示</el-tag>
                <el-tag v-else type="info" >隐藏</el-tag>
            </template>
        </el-table-column>

        <el-table-column prop="orderNum" label="排序号" />
        <el-table-column prop="addTime" label="添加时间" />
        <el-table-column label="操作" width="200">
            <template #default="scope">
                <el-button @click="editDialog.showEdit(0, scope.row.id)" type="text">添加子级</el-button>
                <el-button @click="editDialog.showEdit(scope.row.id)" type="text">编辑</el-button>
                <el-popconfirm title="确定要删除这条数据吗？" @confirm="deleteData(scope.row)">
                    <template #reference>
                        <el-button type="text">删除</el-button>
                    </template>
                </el-popconfirm>
            </template>
        </el-table-column>
    </el-table>
    <EditCategoryDialog ref="editDialog" @edit="getList()"></EditCategoryDialog>
</template>

<style lang="scss" scoped>
</style>
